import time

import xlrd
import pandas as pd
import requests
import json
import os
import datetime


def get_download_url(rawurl):
    url = "http://10.10.50.23:8088/cms/file/upload/resource/pre-sign-url"
    headers = {
        "Accept": "*/*"
    }
    body = {
        "originUrl": rawurl
    }
    r = requests.post(url=url, headers=headers, json=body)
    redict = json.loads(r.text)
    if redict["code"] == 0:
        return redict["data"]
    else:
        return "fail"

startt = datetime.datetime.now()
path = "0314机检数据--正式任务.xlsx"
excel = pd.read_excel(path, sheet_name=0)

n = 0
downurl = []
droplist = []
for i in range(len(excel)):

    rate = excel.iloc[i,25]
    if rate <= 15.0:
        #print(rate,type(rate))
        oriurl = excel.iloc[i,4]
        downurl.append(get_download_url(oriurl.strip()))
        time.sleep(0.01)
    else:
        droplist.append(i)
excel.drop(excel.index[droplist],inplace=True)
print(len(downurl))
print(len(excel))
excel.insert(5,"下载链接",downurl)
savepath = r"C:\work\project1\changhuirong"
with pd.ExcelWriter(os.path.join(savepath,"aaa.xlsx"),engine='xlsxwriter',engine_kwargs={'options':{"strings_to_urls":False}}) as w:
    excel.to_excel(w,sheet_name="Sheet1",index=False,encoding = "utf-8")

endt = datetime.datetime.now()
print(endt-startt)
